package com.dinzeer.cialloblade.se;

import com.dinzeer.cialloblade.sound.SoundRegsitry;
import mods.flammpfeil.slashblade.capability.slashblade.ISlashBladeState;
import mods.flammpfeil.slashblade.event.SlashBladeEvent;
import mods.flammpfeil.slashblade.registry.ComboStateRegistry;
import mods.flammpfeil.slashblade.registry.specialeffects.SpecialEffect;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.level.Level;
import net.minecraft.util.RandomSource;

@Mod.EventBusSubscriber
public class Ciallo extends SpecialEffect {
    public Ciallo() {
        super(30);
    }

    @SubscribeEvent
    public static void onHitEntity(SlashBladeEvent.HitEvent event){
        ISlashBladeState state=event.getSlashBladeState();
        if (state.hasSpecialEffect(SERegsitry.CIALLO.getId())){
            if (!(event.getUser() instanceof Player player))return;
            if (SpecialEffect.isEffective(SERegsitry.CIALLO.getId(), player.experienceLevel)){
                Level world = player.level();

                    if (player.getRandom().nextInt(2)==1){
                        world.playSound( null, player.getX(), player.getY(), player.getZ(), SoundRegsitry.DOCIALLO.get(), SoundSource.PLAYERS,
                                player.getRandom().nextFloat(), 1.0F);
                    }else {
                        world.playSound( null, player.getX(), player.getY(), player.getZ(), SoundRegsitry.DOCIALLO2.get(), SoundSource.PLAYERS,
                                player.getRandom().nextFloat(), 1.0F);
                    }

            }
        }
    }
    @SubscribeEvent
    public static void onUpdate(SlashBladeEvent.UpdateEvent event){
        ISlashBladeState state=event.getSlashBladeState();
        if (state.hasSpecialEffect(SERegsitry.CIALLO.getId())){
            if (!(event.getEntity() instanceof Player player))return;
            if (SpecialEffect.isEffective(SERegsitry.CIALLO.getId(), player.experienceLevel)) {
                if (state.getProudSoulCount()<1000){
                    Level world = player.level();
                    state.setProudSoulCount(1000);

                        world.playSound( null, player.getX(), player.getY(), player.getZ(), SoundRegsitry.DOCIALLO.get(), SoundSource.PLAYERS,
                                player.getRandom().nextFloat(), 1.0F);

                }
            }
        }
    }
    @SubscribeEvent
    public static void doSlash(SlashBladeEvent.DoSlashEvent event){
        ISlashBladeState state=event.getSlashBladeState();
        if (state.hasSpecialEffect(SERegsitry.CIALLO.getId())){
            if (!(event.getUser() instanceof Player player))return;
            if (SpecialEffect.isEffective(SERegsitry.CIALLO.getId(), player.experienceLevel)){
                Level world = player.level();

                    if (state.getComboSeq()==(ComboStateRegistry.WAVE_EDGE_VERTICAL.getId())){

                            world.playSound( null, player.getX(), player.getY(), player.getZ(), SoundRegsitry.DOSLASH.get(), SoundSource.PLAYERS,
                                    player.getRandom().nextFloat(), 1.0F);

                    }
                if (state.getComboSeq()==(ComboStateRegistry.AERIAL_RAVE_A1.getId())) {

                        world.playSound(null, player.getX(), player.getY(), player.getZ(), SoundRegsitry.SENPAI.get(), SoundSource.PLAYERS,
                                player.getRandom().nextFloat(), 1.0F);

                }

                if (player.isShiftKeyDown() ){

                        world.playSound( null, player.getX(), player.getY(), player.getZ(), SoundRegsitry.DOCIALLO2.get(), SoundSource.PLAYERS,
                                player.getRandom().nextFloat(), 1.0F);

                }

            }
        }
    }
}